/********************************************************************************
 *	Copyright 2011 Gerry Weirich
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at 
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *	$Id: Cluster.scala 4d016ee9cd0e 2011/05/04 06:13:56 rgw $
 ********************************************************************************/

package ch.rgw.cybert

import scala.collection.immutable.ListSet
import scala.collection.JavaConversions._

/**
 * A cluster defines an environment where a Quant lives. 
 * The environment is a Set containing all Nodes with similar Quants.
 */
class Cluster{

	def this(that:Cluster){
		this()
		relations=ListSet[String]() ++ that.relations
	}
	
	def setRelations(list:java.util.List[String]){
		relations=ListSet[String]() ++ list
	}
	
	/** return a java List containing the environemnt */
	def toList : java.util.List[String] = new java.util.ArrayList[String](relations)
	
	private var relations=ListSet[String]()
	
	/** empty the cluster */
	def clear = relations=ListSet[String]()
	
	/** add a new relation to the environment */
	def addRelation(rel:String) = relations = relations + rel;
 
	/**
	 * calculate the relationship from this cluster to another one. 
	 * @param that the other cluster
	 * @return the degree of relationship, expressed as number of matching relations
	 */
	def relationship(that: Cluster) = (relations.size+that.relations.size)-(relations ++ that.relations).size	
 
}